package br.edu.ufcg.splab.io;

import static org.junit.Assert.assertTrue;

import java.io.FileNotFoundException;

import org.junit.Test;

import br.edu.ufcg.splab.core.InterfaceGenerate;
import br.edu.ufcg.splab.core.InterfaceGraph;
import br.edu.ufcg.splab.exceptions.LTSBTException;
import br.edu.ufcg.splab.generator.TestCaseGenerator;
import br.edu.ufcg.splab.generator.TestSuite;
import br.edu.ufcg.splab.parser.GraphToAnnotatedGraphParser;
import br.edu.ufcg.splab.util.ReadTGF;

public class TestLinkXMLPreAndPostConditionWriterTest {

	@Test
	public void testWithPrecondition() {
		try {
			ReadTGF TGFReader = new ReadTGF();
			String graphOneConditionBeginningFilePath = "./test-data/input/OneConditionBegining.tgf";
			InterfaceGraph correspondentGraph = TGFReader.getGraph(graphOneConditionBeginningFilePath);
			InterfaceGraph annotatedGraph = new GraphToAnnotatedGraphParser().graphContraction(correspondentGraph);
			
				assertTrue(annotatedGraph.getEdges().size() == 5);
				assertTrue(annotatedGraph.getStates().values().size() == 6);
	
			InterfaceGenerate generator = new TestCaseGenerator();
			TestSuite generatedSuite = generator.generate(annotatedGraph);
	
				assertTrue(generatedSuite.size() == 2);
	
			TestLinkXMLPreAndPostConditionWriter writer = new TestLinkXMLPreAndPostConditionWriter();
			writer.write(generatedSuite, "./test-data/output/OneConditionBegining.xml");

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (LTSBTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void testWithPreAndPostcondition() {
		try {
			ReadTGF TGFReader = new ReadTGF();
			String graphOneConditionBeginningFilePath = "./test-data/input/OneConditionBeginingOneEnd.tgf";
			InterfaceGraph correspondentGraph = TGFReader.getGraph(graphOneConditionBeginningFilePath);
			InterfaceGraph annotatedGraph = new GraphToAnnotatedGraphParser().graphContraction(correspondentGraph);
			
				assertTrue(annotatedGraph.getEdges().size() == 6);
				assertTrue(annotatedGraph.getStates().values().size() == 7);
	
			InterfaceGenerate generator = new TestCaseGenerator();
			TestSuite generatedSuite = generator.generate(annotatedGraph);
	
				assertTrue(generatedSuite.size() == 2);
	
			TestLinkXMLPreAndPostConditionWriter writer = new TestLinkXMLPreAndPostConditionWriter();
			writer.write(generatedSuite, "./test-data/output/OneConditionBeginingOneEnd.xml");

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (LTSBTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void testWithPostcondition() {
		try {
			ReadTGF TGFReader = new ReadTGF();
			String graphOneConditionBeginningFilePath = "./test-data/input/OneConditionEnd.tgf";
			InterfaceGraph correspondentGraph = TGFReader.getGraph(graphOneConditionBeginningFilePath);
			InterfaceGraph annotatedGraph = new GraphToAnnotatedGraphParser().graphContraction(correspondentGraph);
			
				assertTrue(annotatedGraph.getEdges().size() == 5);
				assertTrue(annotatedGraph.getStates().values().size() == 6);
	
			InterfaceGenerate generator = new TestCaseGenerator();
			TestSuite generatedSuite = generator.generate(annotatedGraph);
	
				assertTrue(generatedSuite.size() == 2);
	
			TestLinkXMLPreAndPostConditionWriter writer = new TestLinkXMLPreAndPostConditionWriter();
			writer.write(generatedSuite, "./test-data/output/OneConditionEnd.xml");

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (LTSBTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
